/*================================================================*
        Copyright (C) 2021 All rights reserved, www.hsby.link.
      	�ļ����ƣ�socket.cc
      	�� �� �ߣ���ɭ����
      	�������ڣ�2022/01/01
 *================================================================*/
#include "iomanager.h"
#include "http/http_session.h"
#include "tcp_server.h"

class TestHttpSessionServer : public hsby::TcpServer {
public:
    void ClientHandle(hsby::Socket::Ptr client) override {
        hsby::http::HttpSession http_session(client);
        auto req = http_session.RecvRequest();
        if (!req) {
            //HSBY_LOG_SYSTEM_DEBUG << "http_session.RecvRequest() error";
            return;
        }
        std::cout << *req;
    }
};

void test_http_session() {
    auto server = std::make_shared<TestHttpSessionServer>();
    if (!server) {
        //HSBY_LOG_SYSTEM_DEBUG << "TestHttpSessionServer::Create() error";
        return;
    }
    if (!server->Init()) {
        //HSBY_LOG_SYSTEM_DEBUG << "TestHttpSessionServer::Init() error";
        return;
    }
    if (!server->Bind(hsby::Ipv4Address::Create("0.0.0.0", 10086))) {
        //HSBY_LOG_SYSTEM_DEBUG << "server->Bind(hsby::Ipv4Address::Create(\"0.0.0.0\", 10086)) error";
        return;
    }
    server->Start();
}

int main() {
    hsby::IoManager iom(1, "TestHttpSession");
    iom.AddTask(test_http_session);
    return 0;
}